package com.xlro.dao;

import com.xlro.db.JDBCUtil;
import com.xlro.domain.Admin;
import com.xlro.domain.User;

import java.sql.ResultSet;
import java.sql.SQLException;

public class LoginDao {

    public User selectOne(String username) {
        User user = null;
        try (
                ResultSet resultSet = JDBCUtil.getInstance().executeQueryRS("select * from " +
                    "borrow_card where username= ?", new Object[]{username})){
            while (resultSet.next()){
                user = new User(resultSet.getString("username")
                ,resultSet.getString("password")
                        ,resultSet.getString("reader"));
            }
        } catch(SQLException e){
            e.printStackTrace();
        }

        return user;
    }

    public Admin selectAdmin(String username) {
        Admin admin = null;
        try (
                ResultSet resultSet = JDBCUtil.getInstance().executeQueryRS("select * from " +
                        "admin where username= ?", new Object[]{username})){
            while (resultSet.next()){
                admin = new Admin(resultSet.getString("username")
                        ,resultSet.getString("password"));
            }
        } catch(SQLException e){
            e.printStackTrace();
        }

        return admin;
    }
}
